import QtQuick
import QtQuick.Controls

Item {
    id: root
    property string path: ""
    property alias sourceComponent: loader.sourceComponent

    signal positionTop()

    Image {
        id: title
        anchors.top: parent.top
        width: parent.width
        fillMode: Image.PreserveAspectFit
        source:  path + "title.jpg"

        Row {
            Button {
                text: "到顶部"
                onClicked: positionTop()
            }

//            Text {
//                anchors.verticalCenter: parent.verticalCenter
//                text: "contentY:" + flickable.contentY.toFixed(1)
//            }
        }
    }

    Loader {
        id: loader
        width: parent.width
        anchors.top: title.bottom
        anchors.bottom: nav.top
        sourceComponent: componentFlickable
    }

    Image {
        id: nav
        anchors.bottom: parent.bottom
        width: parent.width
        fillMode: Image.PreserveAspectFit
        source:  path + "appBar.jpg"
    }

    Component {
        id: componentFlickable
        Item {
            Flickable {
                id: flickable
                objectName: root.objectName
                anchors.fill: parent
                clip: true
                contentHeight: listImage.height
                Image {
                    id: listImage
                    width: parent.width
                    fillMode: Image.PreserveAspectFit
                    source: path + "listView.jpg"
                }

                Connections {
                    target: root
                    function onPositionTop() {
                        flickable.contentY = 0
                    }
                }

                onVisibleChanged: {
                    console.log("flickable.visible:",flickable.visible);
                }
            }
        }
    }
}
